package org.dfg.corejava.jdk6.compiler;

import java.io.File;
import java.io.IOException;

import javax.tools.JavaCompiler;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;

/*
 * 动态编译
 */
public class T1 {
	public static void main(String[] args) throws IOException {
		JavaCompiler jc = ToolProvider.getSystemJavaCompiler();

		StandardJavaFileManager m = jc.getStandardFileManager(null, null, null);

		String path = Thread.currentThread().getContextClassLoader()
				.getResource("HelloWorld.java").getFile();
		File file = new File(path);

		Iterable i = m.getJavaFileObjects(file);

		// 执行编译
		jc.getTask(null, m, null, null, null, i).call();
		// 通过反射获取
		// ....

		m.close();
	}
}
